package com.cheng.student.controller.filter;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "Filter2"
        ,urlPatterns = {"/teacher/*"})
public class Power1Filter
        implements Filter
{
    public void init(FilterConfig config)
            throws ServletException
    {
    }

    public void destroy()
    {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws ServletException, IOException
    {
        System.out.println(((HttpServletRequest) request).getSession().getAttribute("power"));
        if (!"0".equals(((HttpServletRequest)request).getSession().getAttribute("power"))
        &&  !"1".equals(((HttpServletRequest)request).getSession().getAttribute("power")))
        {
            ((HttpServletResponse)response).getWriter().write("您无权限");
            return;
        }
        chain.doFilter(request, response);
    }
}
